package com.yonyou.pmclouds.workflow.util;

import com.yonyou.pmclouds.basecom.util.CommonFieldConst;

import java.lang.reflect.Field;

/**
 * @Description: 单据字段编码转换，处理各单据字段格式不一致问题
 * @Author: zhangzhonghao
 * @Date: 2020-04-18
 */
public class BillFieldNameFormatCoverUtil {

    public static String getBillStatusFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String billStatusField = CommonFieldConst.BILLSTATUS;

        for(Field field : fields){
            if("billStatus".equals(field.getName())){
                billStatusField = "billStatus";
                break;
            }else if("bill_status".equals(field.getName())){
                billStatusField = "bill_status";
                break;
            }
        }

        return billStatusField;
    }

    public static String getPkProjectFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String pkProjectField = CommonFieldConst.PK_PROJECT;

        for(Field field : fields){
            if("pkProject".equals(field.getName())){
                pkProjectField = "pkProject";
                break;
            }else if("pkproject".equals(field.getName())){
                pkProjectField = "pkproject";
                break;
            }
        }

        return pkProjectField;
    }

    public static String getBillTypeFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String billTypeField = CommonFieldConst.BILL_TYPE;

        for(Field field : fields){
            if("billType".equals(field.getName())){
                billTypeField = "billType";
                break;
            }else if("billtype".equals(field.getName())){
                billTypeField = "billtype";
                break;
            }
        }

        return billTypeField;
    }

    public static String getBillPkTenantFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String pkTenantField = CommonFieldConst.PK_TENANT;

        for(Field field : fields){
            if("pk_tenant".equals(field.getName())){
                pkTenantField = "pk_tenant";
                break;
            }else if("pktenant".equals(field.getName())){
                pkTenantField = "pktenant";
                break;
            }
        }

        return pkTenantField;
    }

    public static String getProjectCodeFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String projectCodeField = CommonFieldConst.PROJECTCODE;

        for(Field field : fields){
            if("project_code".equals(field.getName())){
                projectCodeField = "project_code";
                break;
            }else if("projectcode".equals(field.getName())){
                projectCodeField = "projectcode";
                break;
            }
        }

        return projectCodeField;
    }

    public static String getProjectNameFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String projectNameField = CommonFieldConst.PROJECTNAME;

        for(Field field : fields){
            if("project_name".equals(field.getName())){
                projectNameField = "project_name";
                break;
            }else if("projectname".equals(field.getName())){
                projectNameField = "projectname";
                break;
            }
        }

        return projectNameField;
    }

    public static String getBillPkProcessFieldName(Object object){
        if(object == null){
            return null;
        }

        Field[] fields = object.getClass().getDeclaredFields();

        String pkProcessField = CommonFieldConst.PK_PROCESS;

        for(Field field : fields){
            if("pkProcess".equals(field.getName())){
                pkProcessField = "pkProcess";
                break;
            }else if("pkprocess".equals(field.getName())){
                pkProcessField = "pkprocess";
                break;
            }
        }

        return pkProcessField;
    }

}
